package com.definesys.smecrailtransit.module.lineCharts.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.base.SmecBaseActivity;
import com.definesys.smecrailtransit.base.SmecBasePresenter;
import com.definesys.smecrailtransit.databinding.ActivityErrorListBinding;
import com.definesys.smecrailtransit.module.lineCharts.adapter.SmecErrorAdapter;
import com.definesys.smecrailtransit.module.lineCharts.beans.EleErrorMsg;
import com.definesys.smecrailtransit.module.lineCharts.beans.YesReport;
import com.definesys.smecrailtransit.widget.TopBarLayout;
import com.github.mzule.activityrouter.annotation.Router;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2018/3/7.
 */
@Router("SmecErrorListActivity")
public class SmecErrorListActivity extends SmecBaseActivity<SmecBasePresenter> {

    private SmecErrorAdapter smecErrorAdapter;
    private int errorType=0;
    private ArrayList<EleErrorMsg> errorEleList=new ArrayList<>();
    private ArrayList<YesReport> faultEleList=new ArrayList<>();
    private ActivityErrorListBinding activityErrorListBinding;

    @Override
    public SmecBasePresenter getPresenter() {
        return new SmecBasePresenter(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityErrorListBinding= DataBindingUtil.setContentView(this, R.layout.activity_error_list);
        getDataFromIntent();
        initView();
    }

    private void getDataFromIntent(){
        errorType=getIntent().getIntExtra("errorType",0);
        Log.e("sss",errorType+"");
        errorEleList=(ArrayList<EleErrorMsg>)getIntent().getSerializableExtra("errEle");
        faultEleList=(ArrayList<YesReport>)getIntent().getSerializableExtra("fauEle");
        smecErrorAdapter=new SmecErrorAdapter(this,errorType);
    }

    private void initView(){
        activityErrorListBinding.topBarLayout.setTopBarListener(new TopBarLayout.TopBarListener() {
            @Override
            public void setOnLeftClickListener() {
                finish();
                appManager.finishActivity();
            }

            @Override
            public void setOnRight1ClickListener() {

            }

            @Override
            public void setOnRight2ClickListener() {

            }
        });
        activityErrorListBinding.recyclerView.setAdapter(smecErrorAdapter);
        activityErrorListBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        if(errorType == 0){
            smecErrorAdapter.setErrorEleList(errorEleList);
        }
        if(errorType == 1){
            activityErrorListBinding.topBarLayout.getTvTextTitle().setText("昨日故障列表");
            smecErrorAdapter.setFaultEleList(faultEleList);
        }

    }
}
